#include "point.h"

using namespace std;

/**
 * load xml to config your program
 */
int read_xml(string				file, 
			 map<string, point> &points,
			 map<int, string>	&log_points,
			 string				&ip, 
			 int				&port, 
			 unsigned int		&node_id)
{
  XMLNode root = XMLNode::openFileHelper("config.xml", "root");
  if (root.isEmpty()) {
    return -1;
  }

  /*
   * set RTDB connection info 
   */
  ip = root.getChildNode(0).getAttributeValue(0);
  port = (atoi)(root.getChildNode(0).getAttributeValue(1));
  node_id = (atoi)(root.getChildNode(1).getAttributeValue(0));
  
  /* 
   * to load the points 
   */
  point p;   
  XMLNode fengji = root.getChildNode(1).getChildNode(0);
  /* point num */
  int p_num = fengji.nChildNode();

  for (int i = 0; i < p_num; ++i) {
    p.pid = (atoi)(fengji.getChildNode(i).getAttributeValue(0));
    p.pn = fengji.getChildNode(i).getAttributeValue(1);
    p.type = (atoi)(fengji.getChildNode(i).getAttributeValue(2));
    points.insert(make_pair(p.pn, p));
	log_points.insert(make_pair(p.pid, p.pn));
  }

  return 0;
}